package com.action;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;

import com.model.User;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.service.UserService;

@Controller
@Transactional
public class ChangeUserAction extends ActionSupport {
	
	@Resource private UserService userservice;

	private static final long serialVersionUID = 1L;
	
	private User user=new User();
	private String username;
	private String password;
	private String userclass;
	
	public String execute() {			
		// HttpServletRequest request = (HttpServletRequest)
		// context.get(ServletActionContext.HTTP_REQUEST);
		// Map session = context.getSession(); //获取sesion
		ActionContext context = ActionContext.getContext();// 获取action上下文
		//HttpServletResponse response=(HttpServletResponse)context.get(ServletActionContext.HTTP_RESPONSE);
		HttpServletRequest request=(HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST);
		username=request.getParameter("username");
		password=request.getParameter("password");
		userclass=userservice.find(username).getUserclass();
		user.setUsername(username);
		user.setPassword(password);
		user.setUserclass(userclass);
		userservice.change(user, username);
		return SUCCESS;	
	}

}
